package cz.uvn.orthopedy.server;

import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import cz.uvn.orthopedy.client.JournalService;
import cz.uvn.orthopedy.client.entity.Doctor;
import cz.uvn.orthopedy.client.entity.Hall;
import cz.uvn.orthopedy.client.entity.Insurance;
import cz.uvn.orthopedy.client.entity.JournalEntry;
import cz.uvn.orthopedy.client.entity.Patient;
import cz.uvn.orthopedy.client.entity.ScheduleEntry;
import cz.uvn.orthopedy.server.jdo.HallJdo;
import cz.uvn.orthopedy.server.jdo.InsuranceJdo;
import cz.uvn.orthopedy.server.jdo.DoctorJdo;
import cz.uvn.orthopedy.server.jdo.JournalJdo;
import cz.uvn.orthopedy.server.jdo.PatientJdo;
import cz.uvn.orthopedy.server.jdo.ScheduleJdo;

public class JournalServiceImpl extends RemoteServiceServlet implements JournalService {

	private static final long serialVersionUID = 452778122709700718L;
	private static final Logger LOG = Logger.getLogger(JournalServiceImpl.class.getName());

	// =====================================
	// ============= Schedule ============== 
	// =====================================

	@Override
	public void initSchedule(ScheduleEntry[] entries) {
		LOG.log(Level.INFO, "initSchedule() successfully executed");
		ScheduleJdo.initSchedule(entries);
	}

	@Override
	public ScheduleEntry[] getScheduleEntries() {
		ScheduleEntry[] entries = ScheduleJdo.getScheduleEntries();
		LOG.log(Level.INFO, "getScheduleEntries()");
		return entries;
	}

	@Override
	public ScheduleEntry[] getSchedule(int day) {
		ScheduleEntry[] schedule = ScheduleJdo.getSchedule(day);
		LOG.log(Level.INFO, "getSchedule()");
		return schedule;
	}

	@Override
	public void createScheduleEntry(ScheduleEntry entry) {
		ScheduleJdo.createScheduleEntry(entry);
		LOG.log(Level.INFO, "createScheduleEntry() created: " + entry);
	}

	@Override
	public void editScheduleEntry(ScheduleEntry entry) {
		ScheduleJdo.editScheduleEntry(entry);
		LOG.log(Level.INFO, "editScheduleEntry() edited: " + entry);
	}

	@Override
	public void deleteScheduleEntry(ScheduleEntry entry) {
		ScheduleJdo.deleteScheduleEntry(entry);
		LOG.log(Level.INFO, "deleteScheduleEntry() deleted: " + entry);
	}

	// =====================================
	// ============= Entries =============== 
	// =====================================

	@Override
	public JournalEntry[] getEntries(Date date) {
		JournalEntry[] entries = JournalJdo.getEntries(date);
		LOG.log(Level.INFO, "getEntries()");
		return entries;
	}

	@Override
	public void createEntry(JournalEntry entry) {
		JournalJdo.createEntry(entry);
		LOG.log(Level.INFO, "createEntry() created: " + entry);
	}

	@Override
	public void editEntry(JournalEntry entry) {
		JournalJdo.editEntry(entry);
		LOG.log(Level.INFO, "editEntry() edited: " + entry);
	}

	@Override
	public void deleteEntry(JournalEntry entry) {
		JournalJdo.deleteEntry(entry);
		LOG.log(Level.INFO, "deleteEntry() deleted: " + entry);
	}

	// =====================================
	// =============== Halls =============== 
	// =====================================
	
	@Override
	public Hall[] getHalls() {
		Hall[] halls = HallJdo.getHalls();
		LOG.log(Level.INFO, "getHalls()");
		return halls;
	}

	@Override
	public void createHall(Hall hall) {
		HallJdo.createHall(hall);
		LOG.log(Level.INFO, "createHall() created: " + hall);
	}

	@Override
	public void editHall(Hall hall) {
		HallJdo.editHall(hall);
		LOG.log(Level.INFO, "editHall() edited: " + hall);
	}

	@Override
	public void deleteHall(Hall hall) {
		HallJdo.deleteHall(hall);
		LOG.log(Level.INFO, "deleteHall() deleted: " + hall);
	}

	// =====================================
	// ============ Insurances ============= 
	// =====================================

	@Override
	public Insurance[] getInsurances() {
		Insurance[] insurances = InsuranceJdo.getInsurances();
		LOG.log(Level.INFO, "getInsurances()");
		return insurances;
	}

	@Override
	public void createInsurance(Insurance insurance) {
		InsuranceJdo.createInsurance(insurance);
		LOG.log(Level.INFO, "createInsurance() created: " + insurance);
	}

	@Override
	public void editInsurance(Insurance insurance) {
		InsuranceJdo.editInsurance(insurance);
		LOG.log(Level.INFO, "editInsurance() edited: " + insurance);
	}

	@Override
	public void deleteInsurance(Insurance insurance) {
		InsuranceJdo.deleteInsurance(insurance);
		LOG.log(Level.INFO, "deleteInsurance() deleted: " + insurance);
	}

	// =====================================
	// ============== Doctors ============== 
	// =====================================
	
	@Override
	public Doctor[] getDoctors() {
		Doctor[] doctors = DoctorJdo.getDoctors();
		LOG.log(Level.INFO, "getDoctors()");
		return doctors;
	}

	@Override
	public void createDoctor(Doctor doctor) {
		DoctorJdo.createDoctor(doctor);
		LOG.log(Level.INFO, "createDoctor() created: " + doctor);
	}

	@Override
	public void editDoctor(Doctor doctor) {
		DoctorJdo.editDoctor(doctor);
		LOG.log(Level.INFO, "editDoctor() edited: " + doctor);
	}

	@Override
	public void deleteDoctor(Doctor doctor) {
		DoctorJdo.deleteDoctor(doctor);
		LOG.log(Level.INFO, "deleteDoctor() deleted: " + doctor);
	}

	// =====================================
	// ============= Patients ============== 
	// =====================================
	
	@Override
	public Patient[] getPatients() {
		Patient[] patient = PatientJdo.getPatients();
		LOG.log(Level.INFO, "getPatients()");
		return patient;
	}

	@Override
	public Long createPatient(Patient patient) {
		Long patientID = PatientJdo.createPatient(patient);
		LOG.log(Level.INFO, "createPatient() created: " + patient);
		return patientID;
	}

	@Override
	public void editPatient(Patient patient) {
		PatientJdo.editPatient(patient);
		LOG.log(Level.INFO, "editPatient() edited: " + patient);
	}

	@Override
	public void deletePatient(Patient patient) {
		PatientJdo.deletePatient(patient);
		LOG.log(Level.INFO, "deletePatient() deleted: " + patient);
	}

}
